<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateSlideshowAPIRequest;
use App\Http\Requests\API\UpdateSlideshowAPIRequest;
use App\Models\Category;
use App\Models\Goods;
use App\Models\Slideshow;
use App\Repositories\SlideshowRepository;
use App\ZL\Controllers\ApiBaseController;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class SlideshowController
 * @package App\Http\Controllers\API
 */

class SlideshowAPIController extends ApiBaseController
{
    /** @var  SlideshowRepository */
    private $slideshowRepository;
    protected $model_name = 'App\Models\Slideshow';
    protected $model_load_array = [
    ];

    public function __construct(SlideshowRepository $slideshowRepo)
    {
        $this->slideshowRepository = $slideshowRepo;
    }

    public function authLimit()
    {
        $shop_id = \request('shop_id',false);
        $res = [];
        if($shop_id && $shop_id>0){
            $res[] =  ['shop_id', $shop_id];
        }
        return $res;
    }

    public function _after_get($array)
    {
        $array = $array->toArray();
        $data = [];
        foreach ($array as $v) {
            $one = [];
            $one['skip_id'] = $v['skip_id'];
            $one['image'] = $v['image'];
            $one['skip_type'] = $v['skip_type'];
            $one['name'] = $v['name'];
            $one['id'] = $v['id'];
            if($v['skip_type']==1){
                $cate = Category::find($v['skip_id']);
                $one['category'] = $cate?$cate->toArray():null;
            }elseif ($v['skip_type']==2){
                $goods = Goods::find($v['skip_id']);
                $one['goods'] = $goods?$goods->toArray():null;
            }
            $data[] = $one;
        }
        return $data;
    }
}
